package com.zry.traced.utils

import android.app.Activity
import android.content.Context
import android.view.inputmethod.InputMethodManager

/**
 * Created by zry on 2017/9/26.
 */

class KeyboardUtils {
    //关闭软键盘的方法
    fun hideKeyboard(context: Activity) {
        val imm:InputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        if (imm.isActive && context.currentFocus != null) {
            if (context.currentFocus!!.windowToken != null) {
                imm.hideSoftInputFromWindow(context.currentFocus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS)
            }
        }
    }

    //打开虚拟键盘
    fun openKeyboard(context: Context) {
        val inputMethodManager:InputMethodManager = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS)
    }
}
